#!/usr/bin/python3
# -*- coding: utf8 -*-
# Date   : 2021/05/28
# Author : Kwan
# Email  : allenxian@live.com
# Blog   : https://my.oschina.net/u/4173440

import logging
from logging.handlers import TimedRotatingFileHandler

def create_logger(filename, typename):
    """
    日志功能
    :param filename: 日志文件名称
    :param typename: 日志标识
    :return: logger
    """
    logger = logging.getLogger(name=typename)
    fh = TimedRotatingFileHandler(filename=filename, when='d', interval=1, backupCount=7, encoding='utf8', utc=True)
    fmt = logging.Formatter('%(asctime)s - %(levelname)s - > %(message)s', '%Y-%m-%d %H:%M:%S')
    logger.setLevel(logging.DEBUG)
    fh.setFormatter(fmt)
    logger.addHandler(fh)
    return logger



